home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume6 / less.patch < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  62.2 KB

  1. Subject: v06i019:  Patches for more/less interoperability (less.patch)
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.UUCP
  4.  
  5. Submitted by: talcott!topaz!lll-crg!csustan!casey
  6. Mod.sources: Volume 6, Issue 19
  7. Archive-name: less.path
  8.  
  9. [ This posting contains a couple of features designed to have less and
  10.   more "interoperate" more easily.  I have edited the prolog Casey
  11.   sent with his submission.  In the next couple of paragraphs, read "I"
  12.   as "Leith (Casey) Leedom," not "Rich $alz."  --r$]
  13.  
  14. I modified less to accept a command line parameter of the form "-number",
  15. used to change the window scrolling size.  Some programs pass this on to
  16. more, so I added it for compatibility.  This is reflected in the updated
  17. manual page.
  18.  
  19. Not all programs that use a pager (e.g., man in the August seismo BSD2.9
  20. distribution) refer to the $PAGER environment variable.  I therefore
  21. wrote a small program designed to supplant /usr/ucb/more, or whatever
  22. the local pager is.  It looks for $PAGER, and executes the indicated
  23. program with the passed parameters, othherwise, it executes the default
  24. pager (moved to somewhere else, like /usr/ucb/More) with the passed
  25. parameters.
  26.  
  27. Also included are new versions of the makefiles, modified for pager_patch.
  28.   I've also included new versions of all the makefiles (only slightly
  29. modified).  The makefiles for Xenix and SYSV should be fixed to indicate
  30. where Xenix and SYSV keep their standard pagers (I have no idea myself) - as
  31. of now, they're both set to /usr/ucb/more.  "Make pager_patch" will make
  32. the pager patch; "make install_pager_patch" will move the OLD_PAGER to
  33. OLD_PAGER_NEW_LOCATION and install the pager patch in OLD_PAGER.
  34.  
  35. Leith (Casey) Leedom                lll-crg.arpa!csustan!casey
  36. Computer Science Department            work: (209) 667-3185
  37. California State University, Stanislaus        home: (209) 634-2775
  38. Turlock, CA  95380
  39.  
  40. -------------------- cut here --------------------
  41. #! /bin/sh
  42. # This is a shell archive, meaning:
  43. # 1. Remove everything above the #! /bin/sh line.
  44. # 2. Save the resulting text in a file.
  45. # 3. Execute the file with /bin/sh (not csh) to create:
  46. #    option.c
  47. #    screen.c
  48. #    command.c
  49. #    less.l
  50. #    pager_patch.c
  51. #    makefile.bsd41
  52. #    makefile.bsd42
  53. #    makefile.sys5
  54. #    makefile.xen
  55. # This archive created: Fri May 30 00:03:32 1986
  56. export PATH; PATH=/bin:/usr/bin:$PATH
  57. if test -f 'option.c'
  58. then
  59.     echo shar: "will not over-write existing file 'option.c'"
  60. else
  61. cat << \SHAR_EOF > 'option.c'
  62. /*
  63.  * Process command line options.
  64.  * Each option is a single letter which controls a program variable.
  65.  * The options have defaults which may be changed via
  66.  * the command line option, or toggled via the "-" command.
  67.  */
  68.  
  69. #include "less.h"
  70.  
  71. #define    toupper(c)    ((c)-'a'+'A')
  72.  
  73. /*
  74.  * Types of options.
  75.  */
  76. #define    BOOL        01    /* Boolean option: 0 or 1 */
  77. #define    TRIPLE        02    /* Triple-valued option: 0, 1 or 2 */
  78. #define    NUMBER        04    /* Numeric option */
  79. #define    NO_TOGGLE    0100    /* Option cannot be toggled with "-" cmd */
  80.  
  81. /*
  82.  * Variables controlled by command line options.
  83.  */
  84. public int p_nbufs, f_nbufs;    /* Number of buffers.  There are two values,
  85.                    one used for input from a pipe and 
  86.                    the other for input from a file. */
  87. public int clean_data;        /* Can we assume the data is "clean"? 
  88.                    (That is, free of nulls, etc) */
  89. public int quiet;        /* Should we suppress the audible bell? */
  90. public int top_search;        /* Should forward searches start at the top 
  91.                    of the screen? (alternative is bottom) */
  92. public int top_scroll;        /* Repaint screen from top?
  93.                    (alternative is scroll from bottom) */
  94. public int pr_type;        /* Type of prompt (short, medium, long) */
  95. public int bs_mode;        /* How to process backspaces */
  96. public int know_dumb;        /* Don't complain about dumb terminals */
  97. public int quit_at_eof;        /* Quit after hitting end of file twice */
  98. public int squeeze;        /* Squeeze multiple blank lines into one */
  99. public int tabstop;        /* Tab settings */
  100. public int back_scroll;        /* Repaint screen on backwards movement */
  101. public int twiddle;        /* Display "~" for lines after EOF */
  102.  
  103. extern int nbufs;
  104. extern int sc_window;
  105. extern char *first_cmd;
  106. extern char *every_first_cmd;
  107.  
  108. #define    DEF_F_NBUFS    5    /* Default for f_nbufs */
  109. #define    DEF_P_NBUFS    12    /* Default for p_nbufs */
  110.  
  111. static struct option
  112. {
  113.     char oletter;        /* The controlling letter (a-z) */
  114.     char otype;        /* Type of the option */
  115.     int odefault;        /* Default value */
  116.     int *ovar;        /* Pointer to the associated variable */
  117.     char *odesc[3];        /* Description of each value */
  118. } option[] =
  119. {
  120.     { 'c', BOOL, 0, &clean_data,
  121.         { "Don't assume data is clean",
  122.           "Assume data is clean",
  123.           NULL
  124.         }
  125.     },
  126.     { 'd', BOOL|NO_TOGGLE, 0, &know_dumb,
  127.         { NULL, NULL, NULL}
  128.     },
  129.     { 'e', BOOL, 0, &quit_at_eof,
  130.         { "Don't quit at end-of-file",
  131.           "Quit at end-of-file",
  132.           NULL
  133.         }
  134.     },
  135.     { 'h', NUMBER, -1, &back_scroll,
  136.         { "Backwards scroll limit is %d lines",
  137.           NULL, NULL
  138.         }
  139.     },
  140.     { 'p', BOOL, 0, &top_scroll,
  141.         { "Repaint by scrolling from bottom of screen",
  142.           "Repaint by painting from top of screen",
  143.           NULL
  144.         }
  145.     },
  146.     { 'x', NUMBER, 8, &tabstop,
  147.         { "Tab stops every %d spaces", 
  148.           NULL, NULL 
  149.         }
  150.     },
  151.     { 's', BOOL, 0, &squeeze,
  152.         { "Don't squeeze multiple blank lines",
  153.           "Squeeze multiple blank lines",
  154.           NULL
  155.         }
  156.     },
  157.     { 't', BOOL, 1, &top_search,
  158.         { "Forward search starts from bottom of screen",
  159.           "Forward search starts from top of screen",
  160.           NULL
  161.         }
  162.     },
  163.     { 'w', BOOL, 1, &twiddle,
  164.         { "Display nothing for lines after end-of-file",
  165.           "Display ~ for lines after end-of-file",
  166.           NULL
  167.         }
  168.     },
  169.     { 'm', TRIPLE, 0, &pr_type,
  170.         { "Prompt with a colon",
  171.           "Prompt with a message",
  172.           "Prompt with a verbose message"
  173.         }
  174.     },
  175.     { 'q', TRIPLE, 0, &quiet,
  176.         { "Ring the bell for errors AND at eof/bof",
  177.           "Ring the bell for errors but not at eof/bof",
  178.           "Never ring the bell"
  179.         }
  180.     },
  181.     { 'u', TRIPLE, 0, &bs_mode,
  182.         { "Underlined text displayed in underline mode",
  183.           "All backspaces cause overstrike",
  184.           "Backspaces print as ^H"
  185.         }
  186.     },
  187.     { 'z', NUMBER, 24, &sc_window,
  188.         { "Scroll window size is %d lines",
  189.           NULL, NULL
  190.         }
  191.     },
  192.     { '\0' }
  193. };
  194.  
  195. public char all_options[64];    /* List of all valid options */
  196.  
  197. /*
  198.  * Initialize each option to its default value.
  199.  */
  200.     public void
  201. init_option()
  202. {
  203.     register struct option *o;
  204.     register char *p;
  205.  
  206.     /*
  207.      * First do special cases, not in option table.
  208.      */
  209.     first_cmd = every_first_cmd = NULL;
  210.     f_nbufs = DEF_F_NBUFS;        /* -bf */
  211.     p_nbufs = DEF_P_NBUFS;        /* -bp */
  212.  
  213.     p = all_options;
  214.     *p++ = 'b';
  215.  
  216.     for (o = option;  o->oletter != '\0';  o++)
  217.     {
  218.         /*
  219.          * Set each variable to its default.
  220.          * Also make a list of all options, in "all_options".
  221.          */
  222.         *(o->ovar) = o->odefault;
  223.         *p++ = o->oletter;
  224.         if (o->otype & TRIPLE)
  225.             *p++ = toupper(o->oletter);
  226.     }
  227.     *p = '\0';
  228. }
  229.  
  230. /*
  231.  * Toggle command line flags from within the program.
  232.  * Used by the "-" command.
  233.  */
  234.     public void
  235. toggle_option(c)
  236.     int c;
  237. {
  238.     register struct option *o;
  239.     char message[100];
  240.     char buf[5];
  241.  
  242.     /*
  243.      * First check for special cases not handled by the option table.
  244.      */
  245.     switch (c)
  246.     {
  247.     case 'b':
  248.         sprintf(message, "%d buffers", nbufs);
  249.         error(message);
  250.         return;
  251.     }
  252.  
  253.  
  254.     for (o = option;  o->oletter != '\0';  o++)
  255.     {
  256.         if ((o->otype & BOOL) && (o->oletter == c) &&
  257.             (o->otype & NO_TOGGLE) == 0)
  258.         {
  259.             /*
  260.              * Boolean option: 
  261.              * just toggle it.
  262.              */
  263.             *(o->ovar) = ! *(o->ovar);
  264.             error(o->odesc[*(o->ovar)]);
  265.             return;
  266.         } else if ((o->otype & TRIPLE) && (o->oletter == c) &&
  267.             (o->otype & NO_TOGGLE) == 0)
  268.         {
  269.             /*
  270.              * Triple-valued option with lower case letter:
  271.              * make it 1 unless already 1, then make it 0.
  272.              */
  273.             *(o->ovar) = (*(o->ovar) == 1) ? 0 : 1;
  274.             error(o->odesc[*(o->ovar)]);
  275.             return;
  276.         } else if ((o->otype & TRIPLE) && (toupper(o->oletter) == c) &&
  277.             (o->otype & NO_TOGGLE) == 0)
  278.         {
  279.             /*
  280.              * Triple-valued option with upper case letter:
  281.              * make it 2 unless already 2, then make it 0.
  282.              */
  283.             *(o->ovar) = (*(o->ovar) == 2) ? 0 : 2;
  284.             error(o->odesc[*(o->ovar)]);
  285.             return;
  286.         } else if ((o->otype & NUMBER) && (o->oletter == c) &&
  287.             (o->otype & NO_TOGGLE) == 0)
  288.         {
  289.             sprintf(message, o->odesc[0], *(o->ovar));
  290.             error(message);
  291.             return;
  292.         }
  293.     }
  294.  
  295.     if (control_char(c))
  296.         sprintf(buf, "^%c", carat_char(c));
  297.     else
  298.         sprintf(buf, "%c", c);
  299.     sprintf(message, "\"-%s\": no such flag.  Use one of \"%s\"", 
  300.         buf, all_options);
  301.     error(message);
  302. }
  303.  
  304. /*
  305.  * Scan an argument (either from command line or from LESS environment 
  306.  * variable) and process it.
  307.  */
  308.     public void
  309. scan_option(s)
  310.     char *s;
  311. {
  312.     register struct option *o;
  313.     register int c;
  314.  
  315.     if (s == NULL)
  316.         return;
  317.  
  318.     next:
  319.     if (*s == '\0')
  320.         return;
  321.     switch (c = *s++)
  322.     {
  323.     case '-':
  324.     case ' ':
  325.     case '\t':
  326.         goto next;
  327.     case '+':
  328.         if (*s == '+')
  329.             every_first_cmd = ++s;
  330.         first_cmd = s;
  331.         return;
  332.     case 'b':
  333.         switch (*s)
  334.         {
  335.         case 'f':
  336.             s++;
  337.             f_nbufs = getnum(&s, 'b');
  338.             break;
  339.         case 'p':
  340.             s++;
  341.             p_nbufs = getnum(&s, 'b');
  342.             break;
  343.         default:
  344.             f_nbufs = p_nbufs = getnum(&s, 'b');
  345.             break;
  346.         }
  347.         goto next;
  348.     case '0':  case '1':  case '2':  case '3':  case '4':
  349.     case '5':  case '6':  case '7':  case '8':  case '9':
  350.         {
  351.             /*
  352.              * Handle special "more" compatibility form "-number"
  353.              * to set the scrolling window size.
  354.              */
  355.             s--;
  356.             sc_window = getnum(&s, '-');
  357.             goto next;
  358.         }
  359.     }
  360.  
  361.     for (o = option;  o->oletter != '\0';  o++)
  362.     {
  363.         if ((o->otype & BOOL) && (o->oletter == c))
  364.         {
  365.             *(o->ovar) = ! o->odefault;
  366.             goto next;
  367.         } else if ((o->otype & TRIPLE) && (o->oletter == c))
  368.         {
  369.             *(o->ovar) = (o->odefault == 1) ? 0 : 1;
  370.             goto next;
  371.         } else if ((o->otype & TRIPLE) && (toupper(o->oletter) == c))
  372.         {
  373.             *(o->ovar) = (o->odefault == 2) ? 0 : 2;
  374.             goto next;
  375.         } else if ((o->otype & NUMBER) && (o->oletter == c))
  376.         {
  377.             *(o->ovar) = getnum(&s, c);
  378.             goto next;
  379.         }
  380.     }
  381.  
  382.     printf("\"-%c\": invalid flag\n", c);
  383.     exit(1);
  384. }
  385.  
  386. /*
  387.  * Translate a string into a number.
  388.  * Like atoi(), but takes a pointer to a char *, and updates
  389.  * the char * to point after the translated number.
  390.  */
  391.     static int
  392. getnum(sp, c)
  393.     char **sp;
  394.     int c;
  395. {
  396.     register char *s;
  397.     register int n;
  398.  
  399.     s = *sp;
  400.     if (*s < '0' || *s > '9')
  401.     {
  402.         printf("number is required after -%c\n", c);
  403.         exit(1);
  404.     }
  405.  
  406.     n = 0;
  407.     while (*s >= '0' && *s <= '9')
  408.         n = 10 * n + *s++ - '0';
  409.     *sp = s;
  410.     return (n);
  411. }
  412. SHAR_EOF
  413. fi
  414. if test -f 'screen.c'
  415. then
  416.     echo shar: "will not over-write existing file 'screen.c'"
  417. else
  418. cat << \SHAR_EOF > 'screen.c'
  419. /*
  420.  * Routines which deal with the characteristics of the terminal.
  421.  * Uses termcap to be as terminal-independent as possible.
  422.  *
  423.  * {{ Someday this should be rewritten to use curses. }}
  424.  */
  425.  
  426. #include "less.h"
  427. #if XENIX
  428. #include <sys/types.h>
  429. #include <sys/ioctl.h>
  430. #endif
  431.  
  432. #if TERMIO
  433. #include <termio.h>
  434. #else
  435. #include <sgtty.h>
  436. #endif
  437.  
  438. /*
  439.  * Strings passed to tputs() to do various terminal functions.
  440.  */
  441. static char
  442.     *sc_pad,        /* Pad string */
  443.     *sc_home,        /* Cursor home */
  444.     *sc_addline,        /* Add line, scroll down following lines */
  445.     *sc_lower_left,        /* Cursor to last line, first column */
  446.     *sc_move,        /* General cursor positioning */
  447.     *sc_clear,        /* Clear screen */
  448.     *sc_eol_clear,        /* Clear to end of line */
  449.     *sc_s_in,        /* Enter standout (highlighted) mode */
  450.     *sc_s_out,        /* Exit standout mode */
  451.     *sc_u_in,        /* Enter underline mode */
  452.     *sc_u_out,        /* Exit underline mode */
  453.     *sc_visual_bell,    /* Visual bell (flash screen) sequence */
  454.     *sc_backspace,        /* Backspace cursor */
  455.     *sc_init,        /* Startup terminal initialization */
  456.     *sc_deinit;        /* Exit terminal de-intialization */
  457. static int dumb;
  458. static int hard;
  459.  
  460. public int auto_wrap;        /* Terminal does \r\n when write past margin */
  461. public int ignaw;        /* Terminal ignores \n immediately after wrap */
  462. public int erase_char, kill_char; /* The user's erase and line-kill chars */
  463. public int sc_width, sc_height;    /* Height & width of screen */
  464. public int sc_window = -1;    /* window size for forward and backward */
  465. public int ul_width, ue_width;    /* Printing width of underline sequences */
  466. public int so_width, se_width;    /* Printing width of standout sequences */
  467.  
  468. /*
  469.  * These two variables are sometimes defined in,
  470.  * and needed by, the termcap library.
  471.  * It may be necessary on some systems to declare them extern here.
  472.  */
  473. /*extern*/ short ospeed;    /* Terminal output baud rate */
  474. /*extern*/ char PC;        /* Pad character */
  475.  
  476. extern int quiet;        /* If VERY_QUIET, use visual bell for bell */
  477. extern int know_dumb;        /* Don't complain about a dumb terminal */
  478. extern int back_scroll;
  479. char *tgetstr();
  480. char *tgoto();
  481.  
  482. /*
  483.  * Change terminal to "raw mode", or restore to "normal" mode.
  484.  * "Raw mode" means 
  485.  *    1. An outstanding read will complete on receipt of a single keystroke.
  486.  *    2. Input is not echoed.  
  487.  *    3. On output, \n is mapped to \r\n.
  488.  *    4. \t is NOT be expanded into spaces.
  489.  *    5. Signal-causing characters such as ctrl-C (interrupt),
  490.  *       etc. are NOT disabled.
  491.  * It doesn't matter whether an input \n is mapped to \r, or vice versa.
  492.  */
  493.     public void
  494. raw_mode(on)
  495.     int on;
  496. {
  497. #if TERMIO
  498.     struct termio s;
  499.     static struct termio save_term;
  500.  
  501.     if (on)
  502.     {
  503.         /*
  504.          * Get terminal modes.
  505.          */
  506.         ioctl(2, TCGETA, &s);
  507.  
  508.         /*
  509.          * Save modes and set certain variables dependent on modes.
  510.          */
  511.         save_term = s;
  512.         ospeed = s.c_cflag & CBAUD;
  513.         erase_char = s.c_cc[VERASE];
  514.         kill_char = s.c_cc[VKILL];
  515.  
  516.         /*
  517.          * Set the modes to the way we want them.
  518.          */
  519.         s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
  520.         s.c_oflag |=  (OPOST|ONLCR|TAB3);
  521.         s.c_oflag &= ~(OCRNL|ONOCR|ONLRET);
  522.         s.c_cc[VMIN] = 1;
  523.         s.c_cc[VTIME] = 0;
  524.     } else
  525.     {
  526.         /*
  527.          * Restore saved modes.
  528.          */
  529.         s = save_term;
  530.     }
  531.     ioctl(2, TCSETAW, &s);
  532. #else
  533.     struct sgttyb s;
  534.     static struct sgttyb save_term;
  535.  
  536.     if (on)
  537.     {
  538.         /*
  539.          * Get terminal modes.
  540.          */
  541.         ioctl(2, TIOCGETP, &s);
  542.  
  543.         /*
  544.          * Save modes and set certain variables dependent on modes.
  545.          */
  546.         save_term = s;
  547.         ospeed = s.sg_ospeed;
  548.         erase_char = s.sg_erase;
  549.         kill_char = s.sg_kill;
  550.  
  551.         /*
  552.          * Set the modes to the way we want them.
  553.          */
  554.         s.sg_flags |= CBREAK;
  555.         s.sg_flags &= ~(ECHO|XTABS);
  556.     } else
  557.     {
  558.         /*
  559.          * Restore saved modes.
  560.          */
  561.         s = save_term;
  562.     }
  563.     ioctl(2, TIOCSETN, &s);
  564. #endif
  565. }
  566.  
  567. static int couldnt = 0;
  568.  
  569.     static void
  570. cannot(s)
  571.     char *s;
  572. {
  573.     if (know_dumb)
  574.         /* 
  575.          * He knows he has a dumb terminal, so don't tell him. 
  576.          */
  577.         return;
  578.  
  579.     printf("WARNING: terminal cannot \"%s\"\n", s);
  580.     couldnt = 1;
  581. }
  582.  
  583. /*
  584.  * Get terminal capabilities via termcap.
  585.  */
  586.     public void
  587. get_term()
  588. {
  589.     char termbuf[1024];
  590.     char *sp;
  591.     static char sbuf[150];
  592.  
  593.     char *getenv();
  594.  
  595.     /*
  596.      * Find out what kind of terminal this is.
  597.      */
  598.     if (tgetent(termbuf, getenv("TERM")) <= 0)
  599.         dumb = 1;
  600.  
  601.     /*
  602.      * Get size of the screen.
  603.      */
  604.     if (dumb || (sc_height = tgetnum("li")) < 0 || tgetflag("hc"))
  605.     {
  606.         /* Oh no, this is a hardcopy terminal. */
  607.         hard = 1;
  608.         sc_height = 24;
  609.     }
  610.     /*
  611.      * This is terrible - the following if "knows" that it is being
  612.      * executed *after* command line and environment options have
  613.      * already been parsed.  Should it be executed in the main program
  614.      * instead?
  615.      */
  616.     if ((sc_window <= 0) || (sc_window >= sc_height))
  617.         sc_window = sc_height-1;
  618.     if (dumb || (sc_width = tgetnum("co")) < 0)
  619.         sc_width = 80;
  620.  
  621.     auto_wrap = tgetflag("am");
  622.     ignaw = tgetflag("xn");
  623.  
  624.     /*
  625.      * Assumes termcap variable "sg" is the printing width of
  626.      * the standout sequence, the end standout sequence,
  627.      * the underline sequence, and the end underline sequence.
  628.      */
  629.     if ((ul_width = tgetnum("sg")) < 0)
  630.         ul_width = 0;
  631.     so_width = se_width = ue_width = ul_width;
  632.  
  633.     /*
  634.      * Get various string-valued capabilities.
  635.      */
  636.     sp = sbuf;
  637.  
  638.     sc_pad = (dumb) ? NULL : tgetstr("pc", &sp);
  639.     if (sc_pad != NULL)
  640.         PC = *sc_pad;
  641.  
  642.     sc_init = (dumb) ? NULL : tgetstr("ti", &sp);
  643.     if (sc_init == NULL)
  644.         sc_init = "";
  645.  
  646.     sc_deinit= (dumb) ? NULL : tgetstr("te", &sp);
  647.     if (sc_deinit == NULL)
  648.         sc_deinit = "";
  649.  
  650.     sc_eol_clear = (dumb) ? NULL : tgetstr("ce", &sp);
  651.     if (hard || sc_eol_clear == NULL || *sc_eol_clear == '\0')
  652.     {
  653.         cannot("clear to end of line");
  654.         sc_eol_clear = "";
  655.     }
  656.  
  657.     sc_clear = (dumb) ? NULL : tgetstr("cl", &sp);
  658.     if (hard || sc_clear == NULL || *sc_clear == '\0')
  659.     {
  660.         cannot("clear screen");
  661.         sc_clear = "\n\n";
  662.     }
  663.  
  664.     sc_move = (dumb) ? NULL : tgetstr("cm", &sp);
  665.     if (hard || sc_move == NULL || *sc_move == '\0')
  666.     {
  667.         /*
  668.          * This is not an error here, because we don't 
  669.          * always need sc_move.
  670.          * We need it only if we don't have home or lower-left.
  671.          */
  672.         sc_move = "";
  673.     }
  674.  
  675.     sc_s_in = (dumb) ? NULL : tgetstr("so", &sp);
  676.     if (hard || sc_s_in == NULL)
  677.         sc_s_in = "";
  678.  
  679.     sc_s_out = (dumb) ? NULL : tgetstr("se", &sp);
  680.     if (hard || sc_s_out == NULL)
  681.         sc_s_out = "";
  682.  
  683.     sc_u_in = (dumb) ? NULL : tgetstr("us", &sp);
  684.     if (hard || sc_u_in == NULL)
  685.         sc_u_in = sc_s_in;
  686.  
  687.     sc_u_out = (dumb) ? NULL : tgetstr("ue", &sp);
  688.     if (hard || sc_u_out == NULL)
  689.         sc_u_out = sc_s_out;
  690.  
  691.     sc_visual_bell = (dumb) ? NULL : tgetstr("vb", &sp);
  692.     if (hard || sc_visual_bell == NULL)
  693.         sc_visual_bell = "";
  694.  
  695.     sc_home = (dumb) ? NULL : tgetstr("ho", &sp);
  696.     if (hard || sc_home == NULL || *sc_home == '\0')
  697.     {
  698.         if (*sc_move == '\0')
  699.         {
  700.             cannot("home cursor");
  701.             /*
  702.              * This last resort for sc_home is supposed to
  703.              * be an up-arrow suggesting moving to the 
  704.              * top of the "virtual screen". (The one in
  705.              * your imagination as you try to use this on
  706.              * a hard copy terminal.)
  707.              */
  708.             sc_home = "|\b^";        
  709.         } else
  710.         {
  711.             /* 
  712.              * No "home" string,
  713.              * but we can use "move(0,0)".
  714.              */
  715.             strcpy(sp, tgoto(sc_move, 0, 0));
  716.             sc_home = sp;
  717.             sp += strlen(sp) + 1;
  718.         }
  719.     }
  720.  
  721.     sc_lower_left = (dumb) ? NULL : tgetstr("ll", &sp);
  722.     if (hard || sc_lower_left == NULL || *sc_lower_left == '\0')
  723.     {
  724.         if (*sc_move == '\0')
  725.         {
  726.             cannot("move cursor to lower left of screen");
  727.             sc_lower_left = "\r";
  728.         } else
  729.         {
  730.             /*
  731.              * No "lower-left" string, 
  732.              * but we can use "move(0,last-line)".
  733.              */
  734.             strcpy(sp, tgoto(sc_move, 0, sc_height-1));
  735.             sc_lower_left = sp;
  736.             sp += strlen(sp) + 1;
  737.         }
  738.     }
  739.  
  740.     /*
  741.      * To add a line at top of screen and scroll the display down,
  742.      * we use "al" (add line) or "sr" (scroll reverse).
  743.      */
  744.     if (dumb)
  745.         sc_addline = NULL;
  746.     else if ((sc_addline = tgetstr("al", &sp)) == NULL || 
  747.          *sc_addline == '\0')
  748.         sc_addline = tgetstr("sr", &sp);
  749.  
  750.     if (hard || sc_addline == NULL || *sc_addline == '\0')
  751.     {
  752.         cannot("scroll backwards");
  753.         sc_addline = "";
  754.         /* Force repaint on any backward movement */
  755.         back_scroll = 0;
  756.     }
  757.  
  758.     if (dumb || tgetflag("bs"))
  759.         sc_backspace = "\b";
  760.     else
  761.     {
  762.         sc_backspace = tgetstr("bc", &sp);
  763.         if (sc_backspace == NULL || *sc_backspace == '\0')
  764.             sc_backspace = "\b";
  765.     }
  766.  
  767.     if (couldnt)
  768.         /* Give him time to read all the "cannot" messages. */
  769.         error("");
  770. }
  771.  
  772.  
  773. /*
  774.  * Below are the functions which perform all the 
  775.  * terminal-specific screen manipulation.
  776.  */
  777.  
  778.  
  779. /*
  780.  * Initialize terminal
  781.  */
  782.     public void
  783. init()
  784. {
  785.     tputs(sc_init, sc_height, putc);
  786. }
  787.  
  788. /*
  789.  * Deinitialize terminal
  790.  */
  791.     public void
  792. deinit()
  793. {
  794.     tputs(sc_deinit, sc_height, putc);
  795. }
  796.  
  797. /*
  798.  * Home cursor (move to upper left corner of screen).
  799.  */
  800.     public void
  801. home()
  802. {
  803.     tputs(sc_home, 1, putc);
  804. }
  805.  
  806. /*
  807.  * Add a blank line (called with cursor at home).
  808.  * Should scroll the display down.
  809.  */
  810.     public void
  811. add_line()
  812. {
  813.     tputs(sc_addline, sc_height, putc);
  814. }
  815.  
  816. /*
  817.  * Move cursor to lower left corner of screen.
  818.  */
  819.     public void
  820. lower_left()
  821. {
  822.     tputs(sc_lower_left, 1, putc);
  823. }
  824.  
  825. /*
  826.  * Ring the terminal bell.
  827.  */
  828.     public void
  829. bell()
  830. {
  831.     if (quiet == VERY_QUIET)
  832.         vbell();
  833.     else
  834.         putc('\7');
  835. }
  836.  
  837. /*
  838.  * Output the "visual bell", if there is one.
  839.  */
  840.     public void
  841. vbell()
  842. {
  843.     if (*sc_visual_bell == '\0')
  844.         return;
  845.     tputs(sc_visual_bell, sc_height, putc);
  846. }
  847.  
  848. /*
  849.  * Clear the screen.
  850.  */
  851.     public void
  852. clear()
  853. {
  854.     tputs(sc_clear, sc_height, putc);
  855. }
  856.  
  857. /*
  858.  * Clear from the cursor to the end of the cursor's line.
  859.  * {{ This must not move the cursor. }}
  860.  */
  861.     public void
  862. clear_eol()
  863. {
  864.     tputs(sc_eol_clear, 1, putc);
  865. }
  866.  
  867. /*
  868.  * Begin "standout" (bold, underline, or whatever).
  869.  */
  870.     public void
  871. so_enter()
  872. {
  873.     tputs(sc_s_in, 1, putc);
  874. }
  875.  
  876. /*
  877.  * End "standout".
  878.  */
  879.     public void
  880. so_exit()
  881. {
  882.     tputs(sc_s_out, 1, putc);
  883. }
  884.  
  885. /*
  886.  * Begin "underline" (hopefully real underlining, 
  887.  * otherwise whatever the terminal provides).
  888.  */
  889.     public void
  890. ul_enter()
  891. {
  892.     tputs(sc_u_in, 1, putc);
  893. }
  894.  
  895. /*
  896.  * End "underline".
  897.  */
  898.     public void
  899. ul_exit()
  900. {
  901.     tputs(sc_u_out, 1, putc);
  902. }
  903.  
  904. /*
  905.  * Erase the character to the left of the cursor 
  906.  * and move the cursor left.
  907.  */
  908.     public void
  909. backspace()
  910. {
  911.     /* 
  912.      * Try to erase the previous character by overstriking with a space.
  913.      */
  914.     tputs(sc_backspace, 1, putc);
  915.     putc(' ');
  916.     tputs(sc_backspace, 1, putc);
  917. }
  918.  
  919. /*
  920.  * Output a plain backspace, without erasing the previous char.
  921.  */
  922.     public void
  923. putbs()
  924. {
  925.     tputs(sc_backspace, 1, putc);
  926. }
  927. SHAR_EOF
  928. fi
  929. if test -f 'command.c'
  930. then
  931.     echo shar: "will not over-write existing file 'command.c'"
  932. else
  933. cat << \SHAR_EOF > 'command.c'
  934. /*
  935.  * User-level command processor.
  936.  */
  937.  
  938. #include "less.h"
  939. #include "position.h"
  940. #include <setjmp.h>
  941.  
  942. extern jmp_buf main_loop;
  943. extern int erase_char, kill_char;
  944. extern int pr_type;
  945. extern int sigs;
  946. extern int ispipe;
  947. extern int quit_at_eof;
  948. extern int hit_eof;
  949. extern int sc_width, sc_height;
  950. extern int sc_window;
  951. extern char *first_cmd;
  952. extern char version[];
  953. extern char current_file[];
  954. extern char *editor;
  955.  
  956. static char cmdbuf[90];        /* Buffer for holding a multi-char command */
  957. static char *cp;        /* Pointer into cmdbuf */
  958. static int cmd_col;        /* Current column of the multi-char command */
  959. static char mcc;        /* The multi-char command letter (e.g. '/') */
  960. static char last_mcc;        /* The previous mcc */
  961.  
  962. /*
  963.  * Reset command buffer (to empty).
  964.  */
  965. cmd_reset()
  966. {
  967.     cp = cmdbuf;
  968. }
  969.  
  970. /*
  971.  * Backspace in command buffer.
  972.  */
  973.     static int
  974. cmd_erase()
  975. {
  976.     if (cp == cmdbuf)
  977.         /*
  978.          * Backspace past beginning of the string:
  979.          * this usually means abort the command.
  980.          */
  981.         return (1);
  982.  
  983.     if (control_char(*--cp))
  984.     {
  985.         /*
  986.          * Erase an extra character, for the carat.
  987.          */
  988.         backspace();
  989.         cmd_col--;
  990.     }
  991.     backspace();
  992.     cmd_col--;
  993.     return (0);
  994. }
  995.  
  996. /*
  997.  * Set up the display to start a new multi-character command.
  998.  */
  999. start_mcc()
  1000. {
  1001.     lower_left();
  1002.     clear_eol();
  1003.     putc(mcc);
  1004.     cmd_col = 1;
  1005. }
  1006.  
  1007. /*
  1008.  * Process a single character of a multi-character command, such as
  1009.  * a number, or the pattern of a search command.
  1010.  */
  1011.     static int
  1012. cmd_char(c)
  1013.     int c;
  1014. {
  1015.     if (c == erase_char)
  1016.     {
  1017.         if (cmd_erase())
  1018.             return (1);
  1019.     } else if (c == kill_char)
  1020.     {
  1021.         /* {{ Could do this faster, but who cares? }} */
  1022.         while (cmd_erase() == 0)
  1023.             ;
  1024.     } else
  1025.     {
  1026.         /*
  1027.          * Append the character to the string,
  1028.          * if there is room in the buffer and on the screen.
  1029.          */
  1030.         if (cp < &cmdbuf[sizeof(cmdbuf)-1] && cmd_col < sc_width-3)
  1031.         {
  1032.             *cp++ = c;
  1033.             if (control_char(c))
  1034.             {
  1035.                 putc('^');
  1036.                 cmd_col++;
  1037.                 c = carat_char(c);
  1038.             }
  1039.             putc(c);
  1040.             cmd_col++;
  1041.         } else
  1042.             bell();
  1043.     }
  1044.     return (0);
  1045. }
  1046.  
  1047. /*
  1048.  * Return the number currently in the command buffer.
  1049.  */
  1050.     static int
  1051. cmd_int()
  1052. {
  1053.     *cp = '\0';
  1054.     cp = cmdbuf;
  1055.     return (atoi(cmdbuf));
  1056. }
  1057.  
  1058. /*
  1059.  * Move the cursor to lower left before executing a command.
  1060.  * This looks nicer if the command takes a long time before
  1061.  * updating the screen.
  1062.  */
  1063.     static void
  1064. cmd_exec()
  1065. {
  1066.     lower_left();
  1067.     flush();
  1068. }
  1069.  
  1070. /*
  1071.  * Display the appropriate prompt.
  1072.  */
  1073.     static void
  1074. prompt()
  1075. {
  1076.     register char *p;
  1077.  
  1078.     if (first_cmd != NULL && *first_cmd != '\0')
  1079.         /*
  1080.          * No prompt necessary if commands are from first_cmd
  1081.          * rather than from the user.
  1082.          */
  1083.         return;
  1084.  
  1085.     /*
  1086.      * Select the proper prompt and display it.
  1087.      */
  1088.     p = pr_string();
  1089.     if (p == NULL)
  1090.         putc(':');
  1091.     else
  1092.     {
  1093.         so_enter();
  1094.         puts(p);
  1095.         so_exit();
  1096.     }
  1097. }
  1098.  
  1099. /*
  1100.  * Get command character.
  1101.  * The character normally comes from the keyboard,
  1102.  * but may come from the "first_cmd" string.
  1103.  */
  1104.     static int
  1105. getcc()
  1106. {
  1107.     if (first_cmd == NULL)
  1108.         return (getc());
  1109.  
  1110.     if (*first_cmd == '\0')
  1111.     {
  1112.         /*
  1113.          * Reached end of first_cmd input.
  1114.          */
  1115.         first_cmd = NULL;
  1116.         if (cp > cmdbuf && position(TOP) == NULL_POSITION)
  1117.         {
  1118.             /*
  1119.              * Command is incomplete, so try to complete it.
  1120.              * There are only two cases:
  1121.              * 1. We have "/string" but no newline.  Add the \n.
  1122.              * 2. We have a number but no command.  Treat as #g.
  1123.              * (This is all pretty hokey.)
  1124.              */
  1125.             if (mcc != ':')
  1126.                 return ('\n'); 
  1127.             else
  1128.                 return ('g');
  1129.         }
  1130.         return (getc());
  1131.     }
  1132.     return (*first_cmd++);
  1133. }
  1134.  
  1135. /*
  1136.  * Main command processor.
  1137.  * Accept and execute commands until a quit command, then return.
  1138.  */
  1139.     public void
  1140. commands()
  1141. {
  1142.     register int c;
  1143.     register int n;
  1144.     register int scroll = 10;
  1145.  
  1146.     mcc = last_mcc = 0;
  1147.  
  1148.     setjmp(main_loop);
  1149.     for (;;)
  1150.     {
  1151.         /*
  1152.          * Display prompt and accept a character.
  1153.          */
  1154.         psignals();    /* See if any signals need processing */
  1155.  
  1156.         if (quit_at_eof && hit_eof > 1)
  1157.             /*
  1158.              * After hitting end-of-file for the second time,
  1159.              * automatically advance to the next file.
  1160.              * If there are no more files, quit.
  1161.              */
  1162.             next_file(1);
  1163.  
  1164.         cmd_reset();
  1165.         lower_left();
  1166.         clear_eol();
  1167.         prompt();
  1168.         c = getcc();
  1169.  
  1170.     again:
  1171.         if (sigs)
  1172.             continue;
  1173.  
  1174.         if (mcc)
  1175.         {
  1176.             /*
  1177.              * We are in a multi-character command.  
  1178.              * All chars until newline go into the command buffer.
  1179.              * (Note that mcc == ':' is a special case that
  1180.              *  means a number is being entered.)
  1181.              */
  1182.             if (mcc != ':' && (c == '\n' || c == '\r'))
  1183.             {
  1184.                 /*
  1185.                  * Execute the command.
  1186.                  */
  1187.                 *cp = '\0';
  1188.                 cmd_exec();
  1189.                 if (mcc == 'E')
  1190.                 {
  1191.                     char *p;
  1192.                     /*
  1193.                      * Ignore leading spaces 
  1194.                      * in the filename.
  1195.                      */
  1196.                     for (p = cmdbuf;  *p == ' ';  p++) ;
  1197.                     edit(p);
  1198. #if SHELL_ESCAPE
  1199.                 } else if (mcc == '!')
  1200.                 {
  1201.                     lsystem(cmdbuf);
  1202.                     error("!done");
  1203.                     first_cmd = "r";    /* Repaint */
  1204. #endif
  1205.                 } else
  1206.                     search(mcc, cmdbuf, n);
  1207.                 mcc = 0;
  1208.             } else
  1209.             {
  1210.                 if (mcc == ':' && (c < '0' || c > '9') &&
  1211.                     c != erase_char && c != kill_char)
  1212.                 {
  1213.                     /*
  1214.                      * This is not part of the number
  1215.                      * we were entering.  Process
  1216.                      * it as a regular character.
  1217.                      */
  1218.                     mcc = 0;
  1219.                     goto again;
  1220.                 }
  1221.  
  1222.                 /*
  1223.                  * Append the char to the command buffer.
  1224.                  */
  1225.                 if (cmd_char(c))
  1226.                 {
  1227.                     /* Abort the multi-char command. */
  1228.                     mcc = 0;
  1229.                     continue;
  1230.                 }
  1231.                 c = getcc();
  1232.                 goto again;
  1233.             }
  1234.         } else switch (c)
  1235.         {
  1236.         case '0': case '1': case '2': case '3': case '4':
  1237.         case '5': case '6': case '7': case '8': case '9':
  1238.             /*
  1239.              * First digit of a number.
  1240.              */
  1241.             mcc = ':';
  1242.             start_mcc();
  1243.             goto again;
  1244.  
  1245.         case 'f':
  1246.         case ' ':
  1247.         case CONTROL('F'):
  1248.             /*
  1249.              * Forward one screen.
  1250.              */
  1251.             n = cmd_int();
  1252.             if (n <= 0)
  1253.                 n = sc_window;
  1254.             forward(n, 1);
  1255.             break;
  1256.  
  1257.         case 'b':
  1258.         case CONTROL('B'):
  1259.             /*
  1260.              * Backward one screen.
  1261.              */
  1262.             n = cmd_int();
  1263.             if (n <= 0)
  1264.                 n = sc_window;
  1265.             backward(n, 1);
  1266.             break;
  1267.  
  1268.         case 'e':
  1269.         case 'j':
  1270.         case '\r':
  1271.         case '\n':
  1272.         case CONTROL('E'):
  1273.             /*
  1274.              * Forward N (default 1) line.
  1275.              */
  1276.             n = cmd_int();
  1277.             if (n <= 0)
  1278.                 n = 1;
  1279.             forward(n, 0);
  1280.             break;
  1281.  
  1282.         case 'y':
  1283.         case 'k':
  1284.         case CONTROL('K'):
  1285.         case CONTROL('Y'):
  1286.             /*
  1287.              * Backward N (default 1) line.
  1288.              */
  1289.             n = cmd_int();
  1290.             if (n <= 0)
  1291.                 n = 1;
  1292.             backward(n, 0);
  1293.             break;
  1294.  
  1295.         case 'd':
  1296.         case CONTROL('D'):
  1297.             /*
  1298.              * Forward N lines 
  1299.              * (default same as last 'd' or 'u' command).
  1300.              */
  1301.             n = cmd_int();
  1302.             if (n > 0)
  1303.                 scroll = n;
  1304.             forward(scroll, 0);
  1305.             break;
  1306.  
  1307.         case 'u':
  1308.         case CONTROL('U'):
  1309.             /*
  1310.              * Forward N lines 
  1311.              * (default same as last 'd' or 'u' command).
  1312.              */
  1313.             n = cmd_int();
  1314.             if (n > 0)
  1315.                 scroll = n;
  1316.             backward(scroll, 0);
  1317.             break;
  1318.  
  1319.         case 'R':
  1320.             /*
  1321.              * Flush buffers, then repaint screen.
  1322.              */
  1323.             ch_init(0);
  1324.             /* Fall thru */
  1325.         case 'r':
  1326.         case CONTROL('R'):
  1327.         case CONTROL('L'):
  1328.             /*
  1329.              * Repaint screen.
  1330.              */
  1331.             repaint();
  1332.             break;
  1333.  
  1334.         case 'g':
  1335.             /*
  1336.              * Go to line N, default beginning of file.
  1337.              */
  1338.             n = cmd_int();
  1339.             if (n <= 0)
  1340.                 n = 1;
  1341.             cmd_exec();
  1342.             jump_back(n);
  1343.             break;
  1344.  
  1345.         case 'p':
  1346.         case '%':
  1347.             /*
  1348.              * Go to a specified percentage into the file.
  1349.              */
  1350.             n = cmd_int();
  1351.             if (n < 0)
  1352.                 n = 0;
  1353.             if (n > 100)
  1354.                 n = 100;
  1355.             cmd_exec();
  1356.             jump_percent(n);
  1357.             break;
  1358.  
  1359.         case 'G':
  1360.             /*
  1361.              * Go to line N, default end of file.
  1362.              */
  1363.             n = cmd_int();
  1364.             cmd_exec();
  1365.             if (n <= 0)
  1366.                 jump_forw();
  1367.             else
  1368.                 jump_back(n);
  1369.             break;
  1370.  
  1371.         case '=':
  1372.         case CONTROL('G'):
  1373.             /*
  1374.              * Print file name, etc.
  1375.              */
  1376.             error(eq_message());
  1377.             break;
  1378.             
  1379.         case 'V':
  1380.             /*
  1381.              * Print version number, without the "@(#)".
  1382.              */
  1383.             error(version+4);
  1384.             break;
  1385.  
  1386.         case 'q':
  1387.             /*
  1388.              * Exit.
  1389.              */
  1390.             return;
  1391.  
  1392.         case '/':
  1393.         case '?':
  1394.             /*
  1395.              * Search for a pattern.
  1396.              * Accept chars of the pattern until \n.
  1397.              */
  1398.             n = cmd_int();
  1399.             if (n <= 0)
  1400.                 n = 1;
  1401.             mcc = last_mcc = c;
  1402.             start_mcc();
  1403.             c = getcc();
  1404.             goto again;
  1405.  
  1406.         case 'n':
  1407.             /*
  1408.              * Repeat previous search.
  1409.              */
  1410.             n = cmd_int();
  1411.             if (n <= 0)
  1412.                 n = 1;
  1413.             mcc = last_mcc;
  1414.             start_mcc();
  1415.             cmd_exec();
  1416.             search(mcc, (char *)NULL, n);
  1417.             mcc = 0;
  1418.             break;
  1419.  
  1420.         case 'h':
  1421.             /*
  1422.              * Help.
  1423.              */
  1424.             help();
  1425.             repaint();
  1426.             break;
  1427.  
  1428.         case 'E':
  1429.             /*
  1430.              * Edit a new file.  Get the filename.
  1431.              */
  1432.             cmd_reset();
  1433.             mcc = 'E';
  1434.             start_mcc();
  1435.             puts("dit: ");    /* This looks nicer */
  1436.             cmd_col += 5;
  1437.             c = getcc();
  1438.             goto again;
  1439.             
  1440. #if SHELL_ESCAPE
  1441.         case '!':
  1442.             /*
  1443.              * Shell escape.
  1444.              */
  1445.             cmd_reset();
  1446.             mcc = '!';
  1447.             start_mcc();
  1448.             c = getcc();
  1449.             goto again;
  1450. #endif
  1451.  
  1452. #if EDITOR
  1453.         case 'v':
  1454.             if (ispipe)
  1455.             {
  1456.                 error("Cannot edit standard input");
  1457.                 break;
  1458.             }
  1459.             sprintf(cmdbuf, "%s %s", editor, current_file);
  1460.             lsystem(cmdbuf);
  1461.             first_cmd = "R";
  1462.             break;
  1463. #endif
  1464.  
  1465.         case 'N':
  1466.             /*
  1467.              * Examine next file.
  1468.              */
  1469.             n = cmd_int();
  1470.             if (n <= 0)
  1471.                 n = 1;
  1472.             next_file(n);
  1473.             break;
  1474.  
  1475.         case 'P':
  1476.             /*
  1477.              * Examine previous file.
  1478.              */
  1479.             n = cmd_int();
  1480.             if (n <= 0)
  1481.                 n = 1;
  1482.             prev_file(n);
  1483.             break;
  1484.  
  1485.         case '-':
  1486.             /*
  1487.              * Toggle a flag setting.
  1488.              */
  1489.             mcc = '-';
  1490.             start_mcc();
  1491.             c = getcc();
  1492.             mcc = 0;
  1493.             if (c == erase_char || c == kill_char)
  1494.                 break;
  1495.             toggle_option(c);
  1496.             break;
  1497.  
  1498.         case 'm':
  1499.             /*
  1500.              * Set a mark.
  1501.              */
  1502.             lower_left();
  1503.             clear_eol();
  1504.             puts("mark: ");
  1505.             c = getcc();
  1506.             if (c == erase_char || c == kill_char)
  1507.                 break;
  1508.             setmark(c);
  1509.             break;
  1510.  
  1511.         case '\'':
  1512.             /*
  1513.              * Go to a mark.
  1514.              */
  1515.             lower_left();
  1516.             clear_eol();
  1517.             puts("goto mark: ");
  1518.             c = getcc();
  1519.             if (c == erase_char || c == kill_char)
  1520.                 break;
  1521.             gomark(c);
  1522.             break;
  1523.  
  1524.         default:
  1525.             bell();
  1526.             break;
  1527.         }
  1528.     }
  1529. }
  1530. SHAR_EOF
  1531. fi
  1532. if test -f 'less.l'
  1533. then
  1534.     echo shar: "will not over-write existing file 'less.l'"
  1535. else
  1536. cat << \SHAR_EOF > 'less.l'
  1537. .TH LESS l
  1538. .SH NAME
  1539. less \- opposite of more
  1540. .SH SYNOPSIS
  1541. .B "less [-cdepstwmMqQuU] [-h\fIn\fB] [-b[fp]\fIn\fB] [-x\fIn\fB] [-[z]\fIn\fB] [+\fIcmd\fB] [\fIname\fB] ..."
  1542. .SH DESCRIPTION
  1543. .I Less
  1544. is a program similar to 
  1545. .I more
  1546. (1), but which allows backwards movement
  1547. in the file as well as forward movement.
  1548. Also,
  1549. .I less
  1550. does not have to read the entire input file before starting,
  1551. so with large input files it starts up faster than text editors like
  1552. .I vi
  1553. (1).
  1554. .I Less
  1555. uses termcap, so it can run on a variety of terminals.
  1556. There is even limited support for hardcopy terminals.
  1557. (On a hardcopy terminal, lines which should be printed at the top
  1558. of the screen are prefixed with an up-arrow.)
  1559. .PP
  1560. Commands are based on both
  1561. .I more
  1562. and
  1563. .I vi.
  1564. Commands may be preceeded by a decimal number, 
  1565. called N in the descriptions below.
  1566. The number is used by some commands, as indicated.
  1567.  
  1568. .SH COMMANDS
  1569. .IP h
  1570. Help: display a summary of these commands.
  1571. If you forget all the other commands, remember this one.
  1572. .PP
  1573. .IP SPACE
  1574. Scroll forward N lines, default one window (see option z below).
  1575. If N is more than the screen size, only one screenful is displayed.
  1576. .PP
  1577. .IP f
  1578. Same as SPACE.
  1579. .PP
  1580. .IP b
  1581. Scroll backward N lines, default one window (see option z below).
  1582. If N is more than the screen size, only one screenful is displayed.
  1583. .PP
  1584. .IP RETURN
  1585. Scroll forward N lines, default 1.
  1586. If N is more than the screen size, the entire N lines are displayed.
  1587. .PP
  1588. .IP e
  1589. Same as RETURN.
  1590. .PP
  1591. .IP j
  1592. Also the same as RETURN.
  1593. .PP
  1594. .IP y
  1595. Scroll backward N lines, default 1.
  1596. If N is more than the screen size, the entire N lines are displayed.
  1597. .IP k
  1598. Same as y.
  1599. .PP
  1600. .IP d
  1601. Scroll forward N lines, default 10.
  1602. If N is specified, it becomes the new default for all d and u commands.
  1603. .PP
  1604. .IP u
  1605. Scroll backward N lines, default 10.
  1606. If N is specified, it becomes the new default for all d and u commands.
  1607. .PP
  1608. .IP r
  1609. Repaint the screen.
  1610. .PP
  1611. .IP R
  1612. Repaint the screen, discarding any buffered input.
  1613. Useful if the file is changing while it is being viewed.
  1614. .PP
  1615. .IP g
  1616. Go to line N in the file, default 1 (beginning of file).
  1617. (Warning: this may be slow if N is large.)
  1618. .PP
  1619. .IP G
  1620. Go to line N in the file, default the end of the file.
  1621. (Warning: this may be slow if standard input, 
  1622. rather than a file, is being read.)
  1623. .PP
  1624. .IP p
  1625. Go to a position N percent into the file.
  1626. N should be between 0 and 100.
  1627. (This is possible if standard input is being read,
  1628. but only if
  1629. .I less
  1630. has already read to the end of the file.
  1631. It is always fast, but not always useful.)
  1632. .PP
  1633. .IP %
  1634. Same as p.
  1635. .PP
  1636. .IP m
  1637. Followed by any lowercase letter, marks the current position with that letter.
  1638. .PP
  1639. .IP "'"
  1640. Followed by any lowercase letter, returns to the position which
  1641. was previously marked with that letter.
  1642. All marks are lost when a new file is examined.
  1643. .PP
  1644. .IP /pattern
  1645. Search forward in the file for the N-th occurence of the pattern.
  1646. N defaults to 1.
  1647. The pattern is a regular expression, as recognized by
  1648. .I ed.
  1649. The search starts at the second line displayed
  1650. (but see the -t option, which changes this).
  1651. .PP
  1652. .IP ?pattern
  1653. Search backward in the file for the N-th occurence of the pattern.
  1654. The search starts at the line immediately before the top line displayed.
  1655. .PP
  1656. .IP n
  1657. Repeat previous search, for N-th occurence of the last pattern.
  1658. .PP
  1659. .IP E [filename]
  1660. Examine a new file.
  1661. If the filename is missing, the "current" file (see the N and P commands
  1662. below) from the list of files in the command line is re-examined.
  1663. .PP
  1664. .IP N
  1665. Examine the next file (from the list of files given in the command line).
  1666. If a number N is specified (not to be confused with the command N),
  1667. the N-th next file is examined.
  1668. .PP
  1669. .IP P
  1670. Examine the previous file.
  1671. If a number N is specified, the N-th previous file is examined.
  1672. .PP
  1673. .IP =
  1674. Prints the name of the file being viewed
  1675. and the byte offset of the bottom line being displayed.
  1676. If possible, it also prints the length of the file
  1677. and the percent of the file above the last displayed line.
  1678. .PP
  1679. .IP \-
  1680. Followed by one of the command line option letters (see below),
  1681. this will toggle the setting of that option
  1682. and print a message describing the new setting.
  1683. .PP
  1684. .IP V
  1685. Prints the version number of 
  1686. .I less 
  1687. being run.
  1688. .PP
  1689. .IP q
  1690. Exits
  1691. .I less.
  1692. .PP
  1693. The following 
  1694. two 
  1695. commands may or may not be valid, depending on your particular installation.
  1696. .PP
  1697. .IP v
  1698. Invokes an editor to edit the current file being viewed.
  1699. The editor is taken from the environment variable EDITOR,
  1700. or defaults to "vi".
  1701. .PP
  1702. .IP "! shell-command"
  1703. Invokes a shell to run the shell-command given.
  1704. .PP
  1705. .SH OPTIONS
  1706. Command line options are described below.
  1707. Options are also taken from the environment variable "LESS".
  1708. (The environment variable is parsed before the command line,
  1709. so command line options override the LESS environment variable.
  1710. Options may be changed while
  1711. .I less 
  1712. is running via the "\-" command.)
  1713. For example, if you like 
  1714. more-style prompting, to avoid typing "less -m ..." each time 
  1715. .I less 
  1716. is invoked, you might tell 
  1717. .I csh:
  1718. .sp
  1719. setenv LESS m
  1720. .sp
  1721. or if you use 
  1722. .I sh:
  1723. .sp
  1724. LESS=m; export LESS
  1725. .IP -s
  1726. The -s flag causes
  1727. consecutive blank lines to be squeezed into a single blank line.
  1728. This is useful when viewing
  1729. .I nroff
  1730. output.
  1731. .IP -t
  1732. Normally, forward searches start just after
  1733. the top displayed line (that is, at the second displayed line).
  1734. Thus forward searches include the currently displayed screen.
  1735. The -t command line option causes forward searches to start 
  1736. just after the bottom line displayed,
  1737. thus skipping the currently displayed screen.
  1738. .IP -m
  1739. Normally,
  1740. .I less
  1741. prompts with a colon.
  1742. The -m command line option causes 
  1743. .I less
  1744. to prompt verbosely like 
  1745. .I more,
  1746. printing the file name and percent into the file.
  1747. .IP -M
  1748. The -M command line option causes 
  1749. .I less
  1750. to prompt even more verbosely than 
  1751. .I more.
  1752. .IP -q
  1753. Normally, if an attempt is made to scroll past the end of the file
  1754. or before the beginning of the file, the terminal bell is rung to
  1755. indicate this fact.
  1756. The -q command line option tells
  1757. .I less
  1758. not to ring the bell at such times.
  1759. If the terminal has a "visual bell", it is used instead.
  1760. .IP -Q
  1761. Even if -q is given, 
  1762. .I less 
  1763. will ring the bell on certain other errors,
  1764. such as typing an invalid character.
  1765. The -Q command line option tells
  1766. .I less
  1767. to be quiet all the time; that is, never ring the terminal bell.
  1768. If the terminal has a "visual bell", it is used instead.
  1769. .IP -e
  1770. Normally the only way to exit less is via the "q" command.
  1771. The -e command line option tells less to automatically exit
  1772. the second time it reaches end-of-file.
  1773. .IP -u
  1774. If the -u command line option is given, 
  1775. backspaces are treated as printable characters;
  1776. that is, they are sent to the terminal when they appear in the input.
  1777. .IP -U
  1778. If the -U command line option is given,
  1779. backspaces are printed as the two character sequence "^H".
  1780. If neither -u nor -U is given,
  1781. backspaces which appear adjacent to an underscore character
  1782. are treated specially:
  1783. the underlined text is displayed 
  1784. using the terminal's hardware underlining capability.
  1785. .IP -w
  1786. Normally,
  1787. .I less
  1788. uses a tilde character to represent lines past the end of the file.
  1789. The -w option causes blank lines to be used instead.
  1790. .IP -d
  1791. Normally,
  1792. .I less
  1793. will complain if the terminal is dumb; that is, lacks some important capability,
  1794. such as the ability to clear the screen or scroll backwards.
  1795. The -d flag suppresses this complaint 
  1796. (but does not otherwise change the behavior of the program on a dumb terminal).
  1797. .IP -p
  1798. Normally, 
  1799. .I less 
  1800. will repaint the screen by scrolling from the bottom of the screen.
  1801. If the -p flag is set, when
  1802. .I less 
  1803. needs to change the entire display, it will clear the screen
  1804. and paint from the top line down.
  1805. .IP -h
  1806. Normally,
  1807. .I less
  1808. will scroll backwards when backwards movement is necessary.
  1809. The -h option specifies a maximum number of lines to scroll backwards.
  1810. If it is necessary to move backwards more than this many lines,
  1811. the screen is repainted in a forward direction.
  1812. (If the terminal does not have the ability to scroll
  1813. backwards, -h0 is implied.)
  1814. .IP -[z]\fIn\fR
  1815. When given a backwards or forwards window command,
  1816. .I less
  1817. will by default scroll backwards or forwards one screenful of lines.
  1818. The -[z]\fIn\fR option changes the default scrolling window size
  1819. to \fIn\fR lines.
  1820. If \fIn\fR is greater than the screen size, the scrolling window size
  1821. will be set to one screenful.
  1822. Note that the z is optional for compatibility with more.
  1823. .IP -x
  1824. The -x\fIn\fR command line option sets tab stops every \fIn\fR positions.
  1825. The default for \fIn\fR is 8.
  1826. .IP -b
  1827. The -b\fIn\fR command line option tells
  1828. .I less
  1829. to use a non-standard buffer size.
  1830. There are two standard (default) buffer sizes,
  1831. one is used when a file is being read and the other
  1832. when a pipe (standard input) is being read.
  1833. The current defaults are 5 buffers for files and 12 for pipes.
  1834. (Buffers are 1024 bytes.)
  1835. The number \fIn\fR specifies a different number of buffers to use.
  1836. The -b may be followed by "f", in which case only 
  1837. the file default is changed, or by "p" in which case only the 
  1838. pipe default is changed.  Otherwise, both are changed.
  1839. .IP -c
  1840. Normally, when data is read by
  1841. .I less,
  1842. it is scanned to ensure that bit 7 (the high order bit) is turned off in
  1843. each byte read, and to ensure that there are no null (zero) bytes in
  1844. the data (null bytes are turned into "@" characters).
  1845. If the data is known to be "clean",
  1846. the -c command line option will tell 
  1847. .I less
  1848. to skip this checking, causing an imperceptible speed improvement.
  1849. (However, if the data is not "clean", unpredicatable results may occur.)
  1850. .IP +
  1851. If a command line option begins with \fB+\fR,
  1852. the remainder of that option is taken to be an initial command to
  1853. .I less.
  1854. For example, +G tells
  1855. .I less
  1856. to start at the end of the file rather than the beginning,
  1857. and +/xyz tells it to start at the first occurence of "xyz" in the file.
  1858. As a special case, +<number> acts like +<number>g; 
  1859. that is, it starts the display at the specified line number
  1860. (however, see the caveat under the "g" command above).
  1861. If the option starts with \fB++\fR, the initial command applies to
  1862. every file being viewed, not just the first one.
  1863.  
  1864. .SH BUGS
  1865. When used on standard input (rather than a file), you can move
  1866. backwards only a finite amount, corresponding to that portion
  1867. of the file which is still buffered.
  1868. SHAR_EOF
  1869. fi
  1870. if test -f 'pager_patch.c'
  1871. then
  1872.     echo shar: "will not over-write existing file 'pager_patch.c'"
  1873. else
  1874. cat << \SHAR_EOF > 'pager_patch.c'
  1875. /*
  1876.  * Special interface that checks for the environment variable PAGER.  If
  1877.  * present, the program specified is executed, otherwise OLD_PAGER_NEW_LOCATION
  1878.  * (specified below).  This program should replace /usr/ucb/more (or whatever
  1879.  * your default pager is) and more should be moved to OLD_PAGER_NEW_LOCATION.
  1880.  * This is essentially a fix for all the programs which *should* check for the
  1881.  * environment variable PAGER, but don't - hopefully it will be obsoleted as
  1882.  * old programs are update to check for PAGER so we can loose the overhead of
  1883.  * reexecuting even this small program ...
  1884.  *
  1885.  * Casey Leedom (lll-crg.arpa!csustan!casey) - 5/29/86
  1886.  */
  1887.  
  1888. #ifndef OLD_PAGER_NEW_LOCATION
  1889. #    define    OLD_PAGER_NEW_LOCATION    "/usr/ucb/More"
  1890. #endif !OLD_PAGER_NEW_LOCATION
  1891.  
  1892. void
  1893. main(argc, argv)
  1894.     int    argc;
  1895.     char    **argv;
  1896. {
  1897.     char    *pager, *getenv();
  1898.  
  1899.     if (!(pager = getenv("PAGER")))
  1900.         pager = OLD_PAGER_NEW_LOCATION;
  1901.     (void) execv(pager, argv);
  1902. }
  1903. SHAR_EOF
  1904. fi
  1905. if test -f 'makefile.bsd41'
  1906. then
  1907.     echo shar: "will not over-write existing file 'makefile.bsd41'"
  1908. else
  1909. cat << \SHAR_EOF > 'makefile.bsd41'
  1910. # Makefile for "less"
  1911. #
  1912. # Invoked as:
  1913. #    make all
  1914. #   or    make install
  1915. # Plain "make" is equivalent to "make all".
  1916. #
  1917. # If you add or delete functions, remake funcs.h by doing:
  1918. #    make newfuncs
  1919. # This depends on the coding convention of function headers looking like:
  1920. #    " \t public <function-type> \n <function-name> ( ... ) "
  1921. #
  1922. # Also provided:
  1923. #    make lint    # Runs "lint" on all the sources.
  1924. #    make clean    # Removes "less" and the .o files.
  1925. #    make clobber    # Pretty much the same as make "clean".
  1926. #
  1927. #    make pager_patch        # makes PAGER environment variable
  1928. #    make install_pager_patch    # catcher and installs it (see below)
  1929.  
  1930. ##########################################################################
  1931. # System-specific parameters
  1932. ##########################################################################
  1933.  
  1934. # Define XENIX if running under XENIX 3.0
  1935. XENIX = 0
  1936.  
  1937. # VOID is 1 if your C compiler supports the "void" type,
  1938. # 0 if it does not.
  1939. VOID = 1
  1940.  
  1941. # off_t is the type which lseek() returns.
  1942. # It is also the type of lseek()'s second argument.
  1943. off_t = long
  1944.  
  1945. # TERMIO is 1 if your system has /usr/include/termio.h.
  1946. # This is normally the case for System 5.
  1947. # If TERMIO is 0 your system must have /usr/include/sgtty.h.
  1948. # This is normally the case for BSD.
  1949. TERMIO = 0
  1950.  
  1951. # SIGSETMASK is 1 if your system has the sigsetmask() call.
  1952. # This is normally the case only for BSD 4.2,
  1953. # not for BSD 4.1 or System 5.
  1954. SIGSETMASK = 0
  1955.  
  1956.  
  1957. ##########################################################################
  1958. # Optional and semi-optional features
  1959. ##########################################################################
  1960.  
  1961. # REGCMP is 1 if your system has the regcmp() function.
  1962. # This is normally the case for System 5.
  1963. # RECOMP is 1 if your system has the re_comp() function.
  1964. # This is normally the case for BSD.
  1965. # If neither is 1, pattern matching is supported, but without metacharacters.
  1966. REGCMP = 0
  1967. RECOMP = 1
  1968.  
  1969. # SHELL_ESCAPE is 1 if you wish to allow shell escapes.
  1970. # (This is possible only if your system supplies the system() function.)
  1971. SHELL_ESCAPE = 0
  1972.  
  1973. # EDITOR is 1 if you wish to allow editor invocation (the "v" command).
  1974. # (This is possible only if your system supplies the system() function.)
  1975. # EDIT_PGM is the name of the (default) editor to be invoked.
  1976. EDITOR = 0
  1977. EDIT_PGM = /usr/ucb/vi
  1978.  
  1979. # parameters to "make install_pager_patch".  OLD_PAGER will be moved to
  1980. # OLD_PAGER_NEW_LOCATION and pager_patch (in this directory) will be installed
  1981. # as OLD_PAGER.  This patch will allow you to set the environment variable
  1982. # PAGER to specify your personal pager preference (is this a security hole?)
  1983. OLD_PAGER = /usr/ucb/more
  1984. OLD_PAGER_NEW_LOCATION = /usr/ucb/More
  1985.  
  1986. # ONLY_RETURN is 1 if you want RETURN to be the only input which
  1987. # will continue past an error message.
  1988. # Otherwise, any key will continue past an error message.
  1989. ONLY_RETURN = 0
  1990.  
  1991.  
  1992. ##########################################################################
  1993. # Compilation environment.
  1994. ##########################################################################
  1995.  
  1996. # LIBS is the list of libraries needed.
  1997. LIBS = -ltermcap
  1998.  
  1999. # INSTALL_LESS is a list of the public versions of less.
  2000. # INSTALL_MAN is a list of the public versions of the manual page.
  2001. INSTALL_LESS =    /usr/local/less
  2002. INSTALL_MAN =    /usr/man/manl/less.l
  2003.  
  2004. # OPTIM is passed to the compiler and the loader.
  2005. # It is normally "-O" but may be, for example, "-g".
  2006. OPTIM = -O
  2007.  
  2008.  
  2009. ##########################################################################
  2010. # Files
  2011. ##########################################################################
  2012.  
  2013. SRC1 =    main.c option.c prim.c 
  2014. SRC2 =    ch.c position.c input.c output.c screen.c \
  2015.     prompt.c line.c signal.c help.c ttyin.c command.c version.c
  2016. SRC =    $(SRC1) $(SRC2)
  2017. OBJ =    main.o option.o prim.o ch.o position.o input.o output.o screen.o \
  2018.     prompt.o line.o signal.o help.o ttyin.o command.o version.o
  2019.  
  2020.  
  2021. ##########################################################################
  2022. # Rules
  2023. ##########################################################################
  2024.  
  2025. DEFS =    "-DTERMIO=$(TERMIO)" \
  2026.     "-DSIGSETMASK=$(SIGSETMASK)" \
  2027.     "-Doff_t=$(off_t)" "-DVOID=$(VOID)" \
  2028.     "-DREGCMP=$(REGCMP)" "-DRECOMP=$(RECOMP)" \
  2029.     "-DSHELL_ESCAPE=$(SHELL_ESCAPE)" \
  2030.     "-DEDITOR=$(EDITOR)" "-DEDIT_PGM=\"$(EDIT_PGM)\"" \
  2031.     "-DONLY_RETURN=$(ONLY_RETURN)" \
  2032.     "-DXENIX=$(XENIX)" \
  2033.     "-DOLD_PAGER_NEW_LOCATION=\"$(OLD_PAGER_NEW_LOCATION)\""
  2034.  
  2035. CFLAGS = $(OPTIM) $(DEFS)
  2036.  
  2037.  
  2038. all: less
  2039.  
  2040. less: $(OBJ)
  2041.     cc $(OPTIM) -o less $(OBJ) $(LIBS)
  2042.  
  2043. install: install_man install_less
  2044.  
  2045. install_man: less.l
  2046.     for f in $(INSTALL_MAN); do  rm -f $$f; cp less.l $$f;  done
  2047.     touch install_man
  2048.     
  2049. install_less: less
  2050.     for f in $(INSTALL_LESS); do  rm -f $$f; cp less $$f;  done
  2051.     touch install_less
  2052.  
  2053. pager_patch: pager_patch.c
  2054.     cc $(CFLAGS) -s -o pager_patch pager_patch.c
  2055.  
  2056. install_pager_patch: pager_patch
  2057.     if [ -s $(OLD_PAGER) -a ! -s $(OLD_PAGER_NEW_LOCATION) ]; then \
  2058.         mv $(OLD_PAGER) $(OLD_PAGER_NEW_LOCATION); \
  2059.         cp pager_patch $(OLD_PAGER); \
  2060.     fi
  2061.     touch install_pager_patch
  2062.  
  2063. $(OBJ): less.h funcs.h
  2064.  
  2065. lint:
  2066.     lint -hp $(DEFS) $(SRC)
  2067.  
  2068. newfuncs:
  2069.     mv funcs.h funcs.h.OLD
  2070.     awk -f mkfuncs.awk $(SRC) >funcs.h
  2071.  
  2072. clean:
  2073.     rm -f $(OBJ) less pager_patch
  2074.  
  2075. clobber:
  2076.     rm -f *.o less pager_patch install_less install_man install_pager_patch
  2077.  
  2078. shar:
  2079.     shar -v INSTALLATION less.l makefile.* *.h *.awk $(SRC1) > less.shar.a
  2080.     shar -v $(SRC2) pager_patch.c > less.shar.b
  2081. SHAR_EOF
  2082. fi
  2083. if test -f 'makefile.bsd42'
  2084. then
  2085.     echo shar: "will not over-write existing file 'makefile.bsd42'"
  2086. else
  2087. cat << \SHAR_EOF > 'makefile.bsd42'
  2088. # Makefile for "less"
  2089. #
  2090. # Invoked as:
  2091. #    make all
  2092. #   or    make install
  2093. # Plain "make" is equivalent to "make all".
  2094. #
  2095. # If you add or delete functions, remake funcs.h by doing:
  2096. #    make newfuncs
  2097. # This depends on the coding convention of function headers looking like:
  2098. #    " \t public <function-type> \n <function-name> ( ... ) "
  2099. #
  2100. # Also provided:
  2101. #    make lint    # Runs "lint" on all the sources.
  2102. #    make clean    # Removes "less" and the .o files.
  2103. #    make clobber    # Pretty much the same as make "clean".
  2104. #
  2105. #    make pager_patch        # makes PAGER environment variable
  2106. #    make install_pager_patch    # catcher and installs it (see below)
  2107.  
  2108.  
  2109. ##########################################################################
  2110. # System-specific parameters
  2111. ##########################################################################
  2112.  
  2113. # Define XENIX if running under XENIX 3.0
  2114. XENIX = 0
  2115.  
  2116. # VOID is 1 if your C compiler supports the "void" type,
  2117. # 0 if it does not.
  2118. VOID = 1
  2119.  
  2120. # off_t is the type which lseek() returns.
  2121. # It is also the type of lseek()'s second argument.
  2122. off_t = long
  2123.  
  2124. # TERMIO is 1 if your system has /usr/include/termio.h.
  2125. # This is normally the case for System 5.
  2126. # If TERMIO is 0 your system must have /usr/include/sgtty.h.
  2127. # This is normally the case for BSD.
  2128. TERMIO = 0
  2129.  
  2130. # SIGSETMASK is 1 if your system has the sigsetmask() call.
  2131. # This is normally the case only for BSD 4.2,
  2132. # not for BSD 4.1 or System 5.
  2133. SIGSETMASK = 1
  2134.  
  2135.  
  2136. ##########################################################################
  2137. # Optional and semi-optional features
  2138. ##########################################################################
  2139.  
  2140. # REGCMP is 1 if your system has the regcmp() function.
  2141. # This is normally the case for System 5.
  2142. # RECOMP is 1 if your system has the re_comp() function.
  2143. # This is normally the case for BSD.
  2144. # If neither is 1, pattern matching is supported, but without metacharacters.
  2145. REGCMP = 0
  2146. RECOMP = 1
  2147.  
  2148. # SHELL_ESCAPE is 1 if you wish to allow shell escapes.
  2149. # (This is possible only if your system supplies the system() function.)
  2150. SHELL_ESCAPE = 0
  2151.  
  2152. # EDITOR is 1 if you wish to allow editor invocation (the "v" command).
  2153. # (This is possible only if your system supplies the system() function.)
  2154. # EDIT_PGM is the name of the (default) editor to be invoked.
  2155. EDITOR = 0
  2156. EDIT_PGM = /usr/ucb/vi
  2157.  
  2158. # parameters to "make install_pager_patch".  OLD_PAGER will be moved to
  2159. # OLD_PAGER_NEW_LOCATION and pager_patch (in this directory) will be installed
  2160. # as OLD_PAGER.  This patch will allow you to set the environment variable
  2161. # PAGER to specify your personal pager preference (is this a security hole?)
  2162. OLD_PAGER = /usr/ucb/more
  2163. OLD_PAGER_NEW_LOCATION = /usr/ucb/More
  2164.  
  2165. # ONLY_RETURN is 1 if you want RETURN to be the only input which
  2166. # will continue past an error message.
  2167. # Otherwise, any key will continue past an error message.
  2168. ONLY_RETURN = 0
  2169.  
  2170.  
  2171. ##########################################################################
  2172. # Compilation environment.
  2173. ##########################################################################
  2174.  
  2175. # LIBS is the list of libraries needed.
  2176. LIBS = -ltermcap
  2177.  
  2178. # INSTALL_LESS is a list of the public versions of less.
  2179. # INSTALL_MAN is a list of the public versions of the manual page.
  2180. INSTALL_LESS =    /usr/local/less
  2181. INSTALL_MAN =    /usr/man/manl/less.l
  2182.  
  2183. # OPTIM is passed to the compiler and the loader.
  2184. # It is normally "-O" but may be, for example, "-g".
  2185. OPTIM = -O
  2186.  
  2187.  
  2188. ##########################################################################
  2189. # Files
  2190. ##########################################################################
  2191.  
  2192. SRC1 =    main.c option.c prim.c
  2193. SRC2 =    ch.c position.c input.c output.c screen.c \
  2194.     prompt.c line.c signal.c help.c ttyin.c command.c version.c
  2195. SRC =    $(SRC1) $(SRC2)
  2196. OBJ =    main.o option.o prim.o ch.o position.o input.o output.o screen.o \
  2197.     prompt.o line.o signal.o help.o ttyin.o command.o version.o
  2198.  
  2199.  
  2200. ##########################################################################
  2201. # Rules
  2202. ##########################################################################
  2203.  
  2204. DEFS =    "-DTERMIO=$(TERMIO)" \
  2205.     "-DSIGSETMASK=$(SIGSETMASK)" \
  2206.     "-Doff_t=$(off_t)" "-DVOID=$(VOID)" \
  2207.     "-DREGCMP=$(REGCMP)" "-DRECOMP=$(RECOMP)" \
  2208.     "-DSHELL_ESCAPE=$(SHELL_ESCAPE)" \
  2209.     "-DEDITOR=$(EDITOR)" "-DEDIT_PGM=\"$(EDIT_PGM)\"" \
  2210.     "-DONLY_RETURN=$(ONLY_RETURN)" \
  2211.     "-DXENIX=$(XENIX)" \
  2212.     "-DOLD_PAGER_NEW_LOCATION=\"$(OLD_PAGER_NEW_LOCATION)\""
  2213.  
  2214. CFLAGS = $(OPTIM) $(DEFS)
  2215.  
  2216.  
  2217. all: less
  2218.  
  2219. less: $(OBJ)
  2220.     cc $(OPTIM) -o less $(OBJ) $(LIBS)
  2221.  
  2222. install: install_man install_less
  2223.  
  2224. install_man: less.l
  2225.     for f in $(INSTALL_MAN); do  rm -f $$f; cp less.l $$f;  done
  2226.     touch install_man
  2227.     
  2228. install_less: less
  2229.     for f in $(INSTALL_LESS); do  rm -f $$f; cp less $$f;  done
  2230.     touch install_less
  2231.  
  2232. pager_patch: pager_patch.c
  2233.     cc $(CFLAGS) -s -o pager_patch pager_patch.c
  2234.  
  2235. install_pager_patch: pager_patch
  2236.     if [ -s $(OLD_PAGER) -a ! -s $(OLD_PAGER_NEW_LOCATION) ]; then \
  2237.         mv $(OLD_PAGER) $(OLD_PAGER_NEW_LOCATION); \
  2238.         cp pager_patch $(OLD_PAGER); \
  2239.     fi
  2240.     touch install_pager_patch
  2241.  
  2242. $(OBJ): less.h funcs.h
  2243.  
  2244. lint:
  2245.     lint -hp $(DEFS) $(SRC)
  2246.  
  2247. newfuncs:
  2248.     mv funcs.h funcs.h.OLD
  2249.     awk -f mkfuncs.awk $(SRC) >funcs.h
  2250.  
  2251. clean:
  2252.     rm -f $(OBJ) less pager_patch
  2253.  
  2254. clobber:
  2255.     rm -f *.o less pager_patch install_less install_man install_pager_patch
  2256.  
  2257. shar:
  2258.     shar -v INSTALLATION less.l makefile.* *.h *.awk $(SRC1) > less.shar.a
  2259.     shar -v $(SRC2) pager_patch.c > less.shar.b
  2260. SHAR_EOF
  2261. fi
  2262. if test -f 'makefile.sys5'
  2263. then
  2264.     echo shar: "will not over-write existing file 'makefile.sys5'"
  2265. else
  2266. cat << \SHAR_EOF > 'makefile.sys5'
  2267. # Makefile for "less"
  2268. #
  2269. # Invoked as:
  2270. #    make all
  2271. #   or    make install
  2272. # Plain "make" is equivalent to "make all".
  2273. #
  2274. # If you add or delete functions, remake funcs.h by doing:
  2275. #    make newfuncs
  2276. # This depends on the coding convention of function headers looking like:
  2277. #    " \t public <function-type> \n <function-name> ( ... ) "
  2278. #
  2279. # Also provided:
  2280. #    make lint    # Runs "lint" on all the sources.
  2281. #    make clean    # Removes "less" and the .o files.
  2282. #    make clobber    # Pretty much the same as make "clean".
  2283. #
  2284. #    make pager_patch        # makes PAGER environment variable
  2285. #    make install_pager_patch    # catcher and installs it (see below)
  2286.  
  2287.  
  2288. ##########################################################################
  2289. # System-specific parameters
  2290. ##########################################################################
  2291.  
  2292. # Define XENIX if running under XENIX 3.0
  2293. XENIX = 0
  2294.  
  2295. # VOID is 1 if your C compiler supports the "void" type,
  2296. # 0 if it does not.
  2297. VOID = 1
  2298.  
  2299. # off_t is the type which lseek() returns.
  2300. # It is also the type of lseek()'s second argument.
  2301. off_t = long
  2302.  
  2303. # TERMIO is 1 if your system has /usr/include/termio.h.
  2304. # This is normally the case for System 5.
  2305. # If TERMIO is 0 your system must have /usr/include/sgtty.h.
  2306. # This is normally the case for BSD.
  2307. TERMIO = 1
  2308.  
  2309. # SIGSETMASK is 1 if your system has the sigsetmask() call.
  2310. # This is normally the case only for BSD 4.2,
  2311. # not for BSD 4.1 or System 5.
  2312. SIGSETMASK = 0
  2313.  
  2314.  
  2315. ##########################################################################
  2316. # Optional and semi-optional features
  2317. ##########################################################################
  2318.  
  2319. # REGCMP is 1 if your system has the regcmp() function.
  2320. # This is normally the case for System 5.
  2321. # RECOMP is 1 if your system has the re_comp() function.
  2322. # This is normally the case for BSD.
  2323. # If neither is 1, pattern matching is supported, but without metacharacters.
  2324. REGCMP = 1
  2325. RECOMP = 0
  2326.  
  2327. # SHELL_ESCAPE is 1 if you wish to allow shell escapes.
  2328. # (This is possible only if your system supplies the system() function.)
  2329. SHELL_ESCAPE = 0
  2330.  
  2331. # EDITOR is 1 if you wish to allow editor invocation (the "v" command).
  2332. # (This is possible only if your system supplies the system() function.)
  2333. # EDIT_PGM is the name of the (default) editor to be invoked.
  2334. EDITOR = 0
  2335. EDIT_PGM = /usr/ucb/vi
  2336.  
  2337. # parameters to "make install_pager_patch".  OLD_PAGER will be moved to
  2338. # OLD_PAGER_NEW_LOCATION and pager_patch (in this directory) will be installed
  2339. # as OLD_PAGER.  This patch will allow you to set the environment variable
  2340. # PAGER to specify your personal pager preference (is this a security hole?)
  2341. OLD_PAGER = /usr/ucb/more
  2342. OLD_PAGER_NEW_LOCATION = /usr/ucb/More
  2343.  
  2344. # ONLY_RETURN is 1 if you want RETURN to be the only input which
  2345. # will continue past an error message.
  2346. # Otherwise, any key will continue past an error message.
  2347. ONLY_RETURN = 0
  2348.  
  2349.  
  2350. ##########################################################################
  2351. # Compilation environment.
  2352. ##########################################################################
  2353.  
  2354. # LIBS is the list of libraries needed.
  2355. LIBS = -lcurses -lPW
  2356.  
  2357. # INSTALL_LESS is a list of the public versions of less.
  2358. # INSTALL_MAN is a list of the public versions of the manual page.
  2359. INSTALL_LESS =    /usr/lbin/less
  2360. INSTALL_MAN =    /usr/man/manl/less.l
  2361.  
  2362. # OPTIM is passed to the compiler and the loader.
  2363. # It is normally "-O" but may be, for example, "-g".
  2364. OPTIM = -O
  2365.  
  2366.  
  2367. ##########################################################################
  2368. # Files
  2369. ##########################################################################
  2370.  
  2371. SRC1 =    main.c option.c prim.c 
  2372. SRC2 =    ch.c position.c input.c output.c screen.c \
  2373.     prompt.c line.c signal.c help.c ttyin.c command.c version.c
  2374. SRC =    $(SRC1) $(SRC2)
  2375. OBJ =    main.o option.o prim.o ch.o position.o input.o output.o screen.o \
  2376.     prompt.o line.o signal.o help.o ttyin.o command.o version.o
  2377.  
  2378.  
  2379. ##########################################################################
  2380. # Rules
  2381. ##########################################################################
  2382.  
  2383. DEFS =    "-DTERMIO=$(TERMIO)" \
  2384.     "-DSIGSETMASK=$(SIGSETMASK)" \
  2385.     "-Doff_t=$(off_t)" "-DVOID=$(VOID)" \
  2386.     "-DREGCMP=$(REGCMP)" "-DRECOMP=$(RECOMP)" \
  2387.     "-DSHELL_ESCAPE=$(SHELL_ESCAPE)" \
  2388.     "-DEDITOR=$(EDITOR)" "-DEDIT_PGM=\"$(EDIT_PGM)\"" \
  2389.     "-DONLY_RETURN=$(ONLY_RETURN)" \
  2390.     "-DXENIX=$(XENIX)" \
  2391.     "-DOLD_PAGER_NEW_LOCATION=\"$(OLD_PAGER_NEW_LOCATION)\""
  2392.  
  2393. CFLAGS = $(OPTIM) $(DEFS)
  2394.  
  2395.  
  2396. all: less
  2397.  
  2398. less: $(OBJ)
  2399.     cc $(OPTIM) -o less $(OBJ) $(LIBS)
  2400.  
  2401. install: install_man install_less
  2402.  
  2403. install_man: less.l
  2404.     for f in $(INSTALL_MAN); do  rm -f $$f; cp less.l $$f;  done
  2405.     touch install_man
  2406.     
  2407. install_less: less
  2408.     for f in $(INSTALL_LESS); do  rm -f $$f; cp less $$f;  done
  2409.     touch install_less
  2410.  
  2411. pager_patch: pager_patch.c
  2412.     cc $(CFLAGS) -s -o pager_patch pager_patch.c
  2413.  
  2414. install_pager_patch: pager_patch
  2415.     if [ -s $(OLD_PAGER) -a ! -s $(OLD_PAGER_NEW_LOCATION) ]; then \
  2416.         mv $(OLD_PAGER) $(OLD_PAGER_NEW_LOCATION); \
  2417.         cp pager_patch $(OLD_PAGER); \
  2418.     fi
  2419.     touch install_pager_patch
  2420.  
  2421. $(OBJ): less.h funcs.h
  2422.  
  2423. lint:
  2424.     lint -hp $(DEFS) $(SRC)
  2425.  
  2426. newfuncs:
  2427.     mv funcs.h funcs.h.OLD
  2428.     awk -f mkfuncs.awk $(SRC) >funcs.h
  2429.  
  2430. clean:
  2431.     rm -f $(OBJ) less pager_patch
  2432.  
  2433. clobber:
  2434.     rm -f *.o less pager_patch install_less install_man install_pager_patch
  2435.  
  2436. shar:
  2437.     shar -v INSTALLATION less.l makefile.* *.h *.awk $(SRC1) > less.shar.a
  2438.     shar -v $(SRC2) pager_patch.c > less.shar.b
  2439. SHAR_EOF
  2440. fi
  2441. if test -f 'makefile.xen'
  2442. then
  2443.     echo shar: "will not over-write existing file 'makefile.xen'"
  2444. else
  2445. cat << \SHAR_EOF > 'makefile.xen'
  2446. # Makefile for "less"
  2447. #
  2448. # Invoked as:
  2449. #    make all
  2450. #   or    make install
  2451. # Plain "make" is equivalent to "make all".
  2452. #
  2453. # If you add or delete functions, remake funcs.h by doing:
  2454. #    make newfuncs
  2455. # This depends on the coding convention of function headers looking like:
  2456. #    " \t public <function-type> \n <function-name> ( ... ) "
  2457. #
  2458. # Also provided:
  2459. #    make lint    # Runs "lint" on all the sources.
  2460. #    make clean    # Removes "less" and the .o files.
  2461. #    make clobber    # Pretty much the same as make "clean".
  2462. #
  2463. #    make pager_patch        # makes PAGER environment variable
  2464. #    make install_pager_patch    # catcher and installs it (see below)
  2465.  
  2466.  
  2467. ##########################################################################
  2468. # System-specific parameters
  2469. ##########################################################################
  2470.  
  2471. # Define XENIX if running under XENIX 3.0
  2472. XENIX = 1
  2473.  
  2474. # VOID is 1 if your C compiler supports the "void" type,
  2475. # 0 if it does not.
  2476. VOID = 1
  2477.  
  2478. # off_t is the type which lseek() returns.
  2479. # It is also the type of lseek()'s second argument.
  2480. off_t = long
  2481.  
  2482. # TERMIO is 1 if your system has /usr/include/termio.h.
  2483. # This is normally the case for System 5.
  2484. # If TERMIO is 0 your system must have /usr/include/sgtty.h.
  2485. # This is normally the case for BSD.
  2486. TERMIO = 1
  2487.  
  2488. # SIGSETMASK is 1 if your system has the sigsetmask() call.
  2489. # This is normally the case only for BSD 4.2,
  2490. # not for BSD 4.1 or System 5.
  2491. SIGSETMASK = 0
  2492.  
  2493.  
  2494. ##########################################################################
  2495. # Optional and semi-optional features
  2496. ##########################################################################
  2497.  
  2498. # REGCMP is 1 if your system has the regcmp() function.
  2499. # This is normally the case for System 5.
  2500. # RECOMP is 1 if your system has the re_comp() function.
  2501. # This is normally the case for BSD.
  2502. # If neither is 1, pattern matching is supported, but without metacharacters.
  2503. REGCMP = 1
  2504. RECOMP = 0
  2505.  
  2506. # SHELL_ESCAPE is 1 if you wish to allow shell escapes.
  2507. # (This is possible only if your system supplies the system() function.)
  2508. SHELL_ESCAPE = 0
  2509.  
  2510. # EDITOR is 1 if you wish to allow editor invocation (the "v" command).
  2511. # (This is possible only if your system supplies the system() function.)
  2512. # EDIT_PGM is the name of the (default) editor to be invoked.
  2513. EDITOR = 0
  2514. EDIT_PGM = /usr/ucb/vi
  2515.  
  2516. # parameters to "make install_pager_patch".  OLD_PAGER will be moved to
  2517. # OLD_PAGER_NEW_LOCATION and pager_patch (in this directory) will be installed
  2518. # as OLD_PAGER.  This patch will allow you to set the environment variable
  2519. # PAGER to specify your personal pager preference (is this a security hole?)
  2520. OLD_PAGER = /usr/ucb/more
  2521. OLD_PAGER_NEW_LOCATION = /usr/ucb/More
  2522.  
  2523. # ONLY_RETURN is 1 if you want RETURN to be the only input which
  2524. # will continue past an error message.
  2525. # Otherwise, any key will continue past an error message.
  2526. ONLY_RETURN = 0
  2527.  
  2528.  
  2529. ##########################################################################
  2530. # Compilation environment.
  2531. ##########################################################################
  2532.  
  2533. # LIBS is the list of libraries needed.
  2534. LIBS = -lcurses -ltermlib
  2535.  
  2536. # INSTALL_LESS is a list of the public versions of less.
  2537. # INSTALL_MAN is a list of the public versions of the manual page.
  2538. INSTALL_LESS =    /usr/lbin/less
  2539. INSTALL_MAN =    /usr/man/manl/less.l
  2540.  
  2541. # OPTIM is passed to the compiler and the loader.
  2542. # It is normally "-O" but may be, for example, "-g".
  2543. OPTIM = -O
  2544.  
  2545.  
  2546. ##########################################################################
  2547. # Files
  2548. ##########################################################################
  2549.  
  2550. SRC1 =    main.c option.c prim.c 
  2551. SRC2 =    ch.c position.c input.c output.c screen.c \
  2552.     prompt.c line.c signal.c help.c ttyin.c command.c version.c
  2553. SRC =    $(SRC1) $(SRC2)
  2554. OBJ =    main.o option.o prim.o ch.o position.o input.o output.o screen.o \
  2555.     prompt.o line.o signal.o help.o ttyin.o command.o version.o
  2556.  
  2557.  
  2558. ##########################################################################
  2559. # Rules
  2560. ##########################################################################
  2561.  
  2562. DEFS =    "-DTERMIO=$(TERMIO)" \
  2563.     "-DSIGSETMASK=$(SIGSETMASK)" \
  2564.     "-Doff_t=$(off_t)" "-DVOID=$(VOID)" \
  2565.     "-DREGCMP=$(REGCMP)" "-DRECOMP=$(RECOMP)" \
  2566.     "-DSHELL_ESCAPE=$(SHELL_ESCAPE)" \
  2567.     "-DEDITOR=$(EDITOR)" "-DEDIT_PGM=\"$(EDIT_PGM)\"" \
  2568.     "-DONLY_RETURN=$(ONLY_RETURN)" \
  2569.     "-DXENIX=$(XENIX)" \
  2570.     "-DOLD_PAGER_NEW_LOCATION=\"$(OLD_PAGER_NEW_LOCATION)\""
  2571.  
  2572. CFLAGS = $(OPTIM) $(DEFS)
  2573.  
  2574.  
  2575. all: less
  2576.  
  2577. less: $(OBJ)
  2578.     cc $(OPTIM) -o less $(OBJ) $(LIBS)
  2579.  
  2580. install: install_man install_less
  2581.  
  2582. install_man: less.l
  2583.     for f in $(INSTALL_MAN); do  rm -f $$f; cp less.l $$f;  done
  2584.     touch install_man
  2585.     
  2586. install_less: less
  2587.     for f in $(INSTALL_LESS); do  rm -f $$f; cp less $$f;  done
  2588.     touch install_less
  2589.  
  2590. pager_patch: pager_patch.c
  2591.     cc $(CFLAGS) -s -o pager_patch pager_patch.c
  2592.  
  2593. install_pager_patch: pager_patch
  2594.     if test -s $(OLD_PAGER) -a ! -s $(OLD_PAGER_NEW_LOCATION) ; then \
  2595.         mv $(OLD_PAGER) $(OLD_PAGER_NEW_LOCATION); \
  2596.         cp pager_patch $(OLD_PAGER); \
  2597.     fi
  2598.     touch install_pager_patch
  2599.  
  2600. $(OBJ): less.h funcs.h
  2601.  
  2602. lint:
  2603.     lint -hp $(DEFS) $(SRC)
  2604.  
  2605. newfuncs:
  2606.     mv funcs.h funcs.h.OLD
  2607.     awk -f mkfuncs.awk $(SRC) >funcs.h
  2608.  
  2609. clean:
  2610.     rm -f $(OBJ) less pager_patch
  2611.  
  2612. clobber:
  2613.     rm -f *.o less pager_patch install_less install_man install_pager_patch
  2614.  
  2615. shar:
  2616.     shar -v INSTALLATION less.l makefile.* *.h *.awk $(SRC1) > less.shar.a
  2617.     shar -v $(SRC2) pager_patch.c > less.shar.b
  2618. SHAR_EOF
  2619. fi
  2620. exit 0
  2621. #    End of shell archive
  2622.  
  2623.  
  2624.